package com.ys.controller.api.base;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ys.entity.base.TbFileInfo;
import com.ys.service.business.TbFileInfoService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

/**
 * 文件信息表
 */
@Controller
@RequestMapping("/api/inter/tbFileInfo")
public class ApiInterTbFileInfoController {

    @Autowired
    private CommonApiService<TbFileInfo> commonApiService;

    @Autowired
    private TbFileInfoService tbFileInfoService;

    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(@ModelAttribute TbFileInfo cond){
    	cond.setStatus(1);
		return commonApiService.searchLay(cond);
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
    @ResponseBody
	public R add(@RequestParam Map<String, Object> params){
		try {
			TbFileInfo entity = JSON.parseObject(JSON.toJSONString(params), TbFileInfo.class);
			return tbFileInfoService.add(entity);
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
		}
	}
	
	/**
	 * 删除(单个)
	 */
	@PostMapping("/delete")
    @ResponseBody
	public R delete(HttpServletRequest request, Long id){
		return tbFileInfoService.deleteFalse(id);
	}
	
	/**
	 * 删除(批量)
	 */
	@PostMapping("/deleteBatch")
    @ResponseBody
	public R deleteBatch(HttpServletRequest request, String ids){
		for(String idStr : ids.split(",")) {
			Long id = Long.parseLong(idStr);
			tbFileInfoService.deleteFalse(id);
		}
		return R.ok("操作完成");
	}
}